#include "ps_support.h"

void ps_memset (void* dest, u32 fill, u32 count){//though fill is u32, you can only put u8 vars in it (due to bitshifting)
	if ( ( ( (u32)dest | count) & 3) == 0)//if it's divisable by 4, quick fill
	{
		count >>= 2;//count/2 :)
		fill = fill | (fill<<8) | (fill<<16) | (fill<<24);//awesome WORKING code
		for (u32 i=0 ; i<count ; i++){
			((u32*)dest)[i] = fill;//fiil dest memory with the value in fill
		}
	}
	else{
		for (u32 i=0 ; i<count ; i++){
			((byte*)dest)[i] = fill;
		}
	}
}

void ps_memcpy (void* dest, void* src, u32 count){
	if ( ( ( (u32)dest | count) & 3) == 0){
		count>>=2;
		for(u32 i=0 ; i<count ; i++){
			((u32*)dest)[i] = ((u32 *)src)[i];
		}
	}
	else{
		for(u32 i=0 ; i<count ; i++){
			((byte*)dest)[i] = ((byte*)src)[i];
		}
	}
}

bool ps_memcmp (void* memloc1, void* memloc2, u32 count){
	while(count){
		count --;
		if(((byte*)memloc1)[count] != ((byte*)memloc2)[count]) return false;
	}
	return true;
}
